package cn.group01.git.controller;

import cn.group01.git.annotations.LogOperation;
import cn.group01.git.common.Operation;
import cn.group01.git.common.ResponseResult;
import cn.group01.git.dto.ImportPageDTO;
import cn.group01.git.entity.GoodsImport;
import cn.group01.git.service.ImportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @description:
 * @author: 黎源
 * @date: 2023/7/13 11:14
 **/

@Controller
@RequestMapping("import")
public class ImportController {

    @Autowired
    private ImportService importService;

    @RequestMapping("list")
    @ResponseBody
    @LogOperation(description = Operation.SELECT,model = "入库模块")
    public ResponseResult list(ImportPageDTO importPageDTO){
        System.out.println(importPageDTO);
        return importService.getList(importPageDTO);
    }

    @PostMapping("add")
    @ResponseBody
    @LogOperation(description = Operation.ADD,model = "入库模块")
    public ResponseResult addImport(@RequestBody GoodsImport goodsImport){
        System.out.println(goodsImport);
        return importService.addImport(goodsImport);
    }
    @GetMapping("getById")
    @ResponseBody
    @LogOperation(description = Operation.SELECT,model = "入库模块")
    public GoodsImport getById(Integer id){
        return importService.getById(id);
    }

    @PostMapping("edit")
    @ResponseBody
    @LogOperation(description = Operation.UPDATE,model = "入库模块")
    public ResponseResult edit(@RequestBody GoodsImport goodsImport){
        return importService.edit(goodsImport);
    }

    // 删除入库
    @GetMapping("delete")
    @ResponseBody
    @LogOperation(description = Operation.DELETE,model = "入库模块")
    public ResponseResult delete(Integer ids[]){

        return importService.delete(ids);
    }

    // 查询结果导出
    @GetMapping("export")
    public void export(ImportPageDTO importPageDTO, HttpServletResponse response){
        importService.export(importPageDTO, response);
    }
}
